package dao

import (
	"fmt"
	"gin-demo/model"
	"gin-demo/tool"
)

type ShopDao struct {
	*tool.Orm
}

const DEFAULT_RANGE = 2

func NewShopDao() *ShopDao {
	return &ShopDao{tool.DbEngine}
}
func (sd *ShopDao) QueryShops(Longitude, latitude float64) []model.Shop {
	var shops []model.Shop

	err := sd.Engine.Where("longitude<=? and longitude>=? and latitude<=? and latitude>=? and status=1",
		Longitude+DEFAULT_RANGE, Longitude-DEFAULT_RANGE, latitude+DEFAULT_RANGE, latitude-DEFAULT_RANGE).Find(&shops)
	if err != nil {
		fmt.Println(err.Error())
		return nil
	}

	return shops
}
